/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simulate;

import java.io.PrintWriter;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;

/**
 *
 * @author thang
 * write sensor data in owl file
 * overwrite file: sensor_ontology.owl
 */
public class OntologyDB {


    //just store light and temperature para at the moment
    public void addData(int[][] windowData){
        PrintWriter outputStream = null;
        try{
            outputStream = new PrintWriter(new FileOutputStream("../../ontology/driving.owl"));
        }
        catch(FileNotFoundException e){
            System.out.println("Error opening the file sensor_ontology.owl");
            System.exit(0);
        }
        System.out.println("Writing to file");
        outputStream.println("<?xml version=\"1.0\"?>");
        outputStream.println("<!DOCTYPE rdf:RDF [");
        outputStream.println("<!ENTITY soupa  \"http://pervasive.semanticweb.org/ont/2004/06/\">");
        outputStream.println("<!ENTITY rdf    \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">");
        outputStream.println("<!ENTITY rdfs   \"http://www.w3.org/2000/01/rdf-schema#\">");
        outputStream.println("<!ENTITY xsd    \"http://www.w3.org/2001/XMLSchema#\">");
        outputStream.println("<!ENTITY owl    \"http://www.w3.org/2002/07/owl#\">");

        outputStream.println("   <!ENTITY foaf   \"http://xmlns.com/foaf/0.1#\">");
        outputStream.println("   <!ENTITY sen    \"http://www.latrobe.edu.au/mtdo/sunspot/sensor_ontology#\">");
        outputStream.println("   ]>");
        outputStream.println("<rdf:RDF");
        outputStream.println("   xmlns:rdf  = \"&rdf;\"");
        outputStream.println("   xmlns:rdfs = \"&rdfs;\"");
        outputStream.println("   xmlns:owl  = \"&owl;\"");
        outputStream.println("   xmlns:xsd  = \"&xsd;\"");
        outputStream.println("   xmlns:foaf = \"&foaf;\"");
        outputStream.println("   xmlns      = \"&sen;\"");
        outputStream.println("   xml:base   = \"http://www.latrobe.edu.au/mtdo/sunspot/sensor_ontology#\">");

        outputStream.println("  <owl:Ontology rdf:about=\"&sen;sensor\">");
        outputStream.println("    <owl:versionInfo>cvs:$Revision: 1.0 $, $Date: 2010/05/27 11:53:17 $</owl:versionInfo>");
        outputStream.println("    <rdfs:label>Sensor Ontology</rdfs:label>");
        outputStream.println("    <rdfs:comment></rdfs:comment>");
        outputStream.println("  </owl:Ontology>");


        outputStream.println("  <owl:Class rdf:ID=\"AcceX\" />");

        outputStream.println("  <owl:DatatypeProperty rdf:ID=\"acceXValue\">");
        outputStream.println("    <rdfs:domain rdf:resource=\"#AcceX\" />");
        outputStream.println("    <rdfs:range rdf:resource=\"&xsd;integer\" />");
        outputStream.println("  </owl:DatatypeProperty>");

        outputStream.println("  <!-- bigger = later -->");

        outputStream.println("  <!-- raw data range acce: -0.5 -> + 0.5, precision: 0.00 -->");
        outputStream.println("  <!-- raw data range acce: -0.5 -> + 0.5, precision: 0.00 -->");
        outputStream.println("  <!-- dlv data range: unsigned number -->");
        outputStream.println("  <!-- convert: (raw data * 100) + 50 -> new range: 0 -> 100 -->");
        outputStream.println("  <!-- with new range 50 meant o in raw data -->");

        outputStream.println("  <!-- window data 1 -->");
        outputStream.println("  <AcceX rdf:ID=\"AcceX1\">");
        outputStream.println("    <acceXValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[0][0] +"</acceXValue>");
        outputStream.println("  </AcceX>");

        outputStream.println("  <AcceY rdf:ID=\"AcceY1\">");
        outputStream.println("    <acceYValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[0][1] +"</acceYValue>");
        outputStream.println("  </AcceY>");

        outputStream.println("  <TiltZ rdf:ID=\"TiltZ1\">");
        outputStream.println("    <tiltZValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[0][2] +"</tiltZValue>");
        outputStream.println("  </TiltZ>");

        outputStream.println("  <!-- window data 2 -->");
        outputStream.println("  <AcceX rdf:ID=\"AcceX2\">");
        outputStream.println("    <acceXValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[1][0] +"</acceXValue>");
        outputStream.println("  </AcceX>");

        outputStream.println("  <AcceY rdf:ID=\"AcceY2\">");
        outputStream.println("    <acceYValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[1][1] +"</acceYValue>");
        outputStream.println("  </AcceY>");

        outputStream.println("  <TiltZ rdf:ID=\"TiltZ2\">");
        outputStream.println("    <tiltZValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[1][2] +"</tiltZValue>");
        outputStream.println("  </TiltZ>");

        outputStream.println("  <!-- window data 3 -->");
        outputStream.println("  <AcceX rdf:ID=\"AcceX3\">");
        outputStream.println("    <acceXValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[2][0] +"</acceXValue>");
        outputStream.println("  </AcceX>");

        outputStream.println("  <AcceY rdf:ID=\"AcceY3\">");
        outputStream.println("    <acceYValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[2][1] +"</acceYValue>");
        outputStream.println("  </AcceY>");

        outputStream.println("  <TiltZ rdf:ID=\"TiltZ3\">");
        outputStream.println("    <tiltZValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[2][2] +"</tiltZValue>");
        outputStream.println("  </TiltZ>");

        outputStream.println("  <!-- window data 4 -->");
        outputStream.println("  <AcceX rdf:ID=\"AcceX4\">");
        outputStream.println("    <acceXValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[3][0] +"</acceXValue>");
        outputStream.println("  </AcceX>");

        outputStream.println("  <AcceY rdf:ID=\"AcceY4\">");
        outputStream.println("    <acceYValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[3][1] +"</acceYValue>");
        outputStream.println("  </AcceY>");

        outputStream.println("  <TiltZ rdf:ID=\"TiltZ4\">");
        outputStream.println("    <tiltZValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[3][2] +"</tiltZValue>");
        outputStream.println("  </TiltZ>");

        outputStream.println("  <!-- window data 5 -->");
        outputStream.println("  <AcceX rdf:ID=\"AcceX5\">");
        outputStream.println("    <acceXValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[4][0] +"</acceXValue>");
        outputStream.println("  </AcceX>");

        outputStream.println("  <AcceY rdf:ID=\"AcceY5\">");
        outputStream.println("    <acceYValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[4][1] +"</acceYValue>");
        outputStream.println("  </AcceY>");

        outputStream.println("  <TiltZ rdf:ID=\"TiltZ5\">");
        outputStream.println("    <tiltZValue rdf:datatype=\"&xsd;positiveInteger\">" + windowData[4][2] +"</tiltZValue>");
        outputStream.println("  </TiltZ>");

        outputStream.println("</rdf:RDF>");

        outputStream.close();
    }


}
